package main

import "fmt"

func main() {
	// 数组的初始化 如果不初始化 默认元素都是零值
	var arr1 [5]int
	//初始化
	arr1 = [5]int{1, 2, 3, 4, 5}
	fmt.Println(arr1)
	//初始化 根据初始值推断数组的长度
	a100 := [...]int{1, 2, 3, 4, 5}
	fmt.Println(a100)
	//初始化
	a3 := [5]int{1, 2}
	fmt.Println(a3)
	//根据索引初始化
	a4 := [...]int{0: 1, 4: 5}
	fmt.Println(a4)
	//数组的遍历

	citys := [...]string{"北京", "上海", "广州", "深圳"}
	//索引遍历
	for i := 0; i < len(citys); i++ {
		fmt.Println(citys[i])
	}
	//for range
	for _, v := range citys {
		fmt.Println(v)
	}
	//多维数组
	var arr5 [3][4]int
	fmt.Println(arr5)
	//多维数组初始化
	arr5 = [3][4]int{
		[4]int{1, 2, 3, 4},
		[4]int{5, 6, 7, 8},
		[4]int{9, 10, 11, 12},
	}
	fmt.Println(arr5)
	//多维数组的遍历
	for _, v := range arr5 {
		fmt.Println(v)
		for _, v2 := range v {
			fmt.Print(v2)
		}
	}
	//数组是值类型 go语言中函数的参数传递默认是值传递 不会改变
	b1 := [3]int{1, 2, 3}
	b2 := b1
	b2[0] = 100
	fmt.Println(b1, b2)
	demo1 := [...]int{1, 3, 5, 7, 8}
	var sum int
	for _, v := range demo1 {
		sum = sum + v
	}
	fmt.Println(sum)
	demo2 := [...]int{1, 3, 5, 7, 8}
	for i := 0; i < len(demo2); i++ {
		for j := i + 1; j < len(demo2); j++ {
			if demo1[i]+demo1[j] == 8 {
				fmt.Printf("%d,%d\n", i, j)
			}
		}
	}
	str := "hello world"
	count := make(map[rune]int)

	for _, r := range str {
		count[r]++
	}

	for k, v := range count {
		fmt.Printf("%c: %d\n", k, v)
	}

}
